﻿function Connect-TSMServer {
    <#
        .SYNOPSIS
            Connect to TSM server
                    
        .DESCRIPTION
            The Format-TSMData function accepts input from TSM in list format and outputs objects
        
        .PARAMETER Data
            The output from DSMADMC.EXE in list format

        .PARAMETER DefaultDisplaySet
            Defines which properties are displayed by default

        .EXAMPLE
            Format-TSMData -Data $data -DefaultDisplaySet $defaultDisplay

        .NOTES
            Contributors:  David Seibel
            Last Revision Date: 09/15/2015

    #>
    [CmdletBinding()]
    Param(
        [Parameter(Position = 0, Mandatory=$true)]
        $Server,

        [Parameter()]
        $WinCredential,
        
        [Parameter()]
        $TSMCredential
    )

    if ($WinCredential -eq $null) {
        $WinCredential = Get-Credential -Message "Enter Windows credentials"        
    }
        
    if ($TSMCredential -eq $null) {
        $TSMCredential = Get-Credential -Message "Enter TSM credentials"
    }

    $global:TSMSession = New-PSSession $Server -Credential $WinCredential
    $global:TSMCredential = $TSMCredential
	$global:TSMServer = $Server
    Invoke-Command -ScriptBlock { Set-Location "C:\Program Files\Tivoli\TSM\server\tsmdiag" } -Session $TSMSession
}